/**
 * @param {number[]} nums
 * @return {number}
 */
 var sumSubseqWidths = function(nums) {
   let path = []
   let sum = 0
  function backtracking(k){
    if(path.length!=0){
      let tempPath = [...path]
      let minNum = Math.min(...tempPath)
      let maxNum = Math.max(...tempPath)
      sum += maxNum - minNum

    }

    for(let i=k;i<nums.length;i++){
      path.push(nums[i])
      backtracking(i+1)
      path.pop()
    }
  }

  backtracking(0)
  
  return sum % (1000000000+7)



};
sumSubseqWidths([5,69,89,92,31,16,25,45,63,40,16,56,24,40,75,82,40,12,50,62,92,44,67,38,92,22,91,24,26,21,100,42,23,56,64,43,95,76,84,79,89,4,16,94,16,77,92,9,30,13])